{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
      " 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1\n",
      " 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2\n",
      " 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n",
      " 2 2]\n",
      "[[5.006      3.428      1.462      0.246     ]\n",
      " [5.91697517 2.77803998 4.20523542 1.29841561]\n",
      " [6.54632887 2.94943079 5.4834877  1.98716063]]\n",
      "[[[0.121765   0.097232   0.016028   0.010124  ]\n",
      "  [0.097232   0.140817   0.011464   0.009112  ]\n",
      "  [0.016028   0.011464   0.029557   0.005948  ]\n",
      "  [0.010124   0.009112   0.005948   0.010885  ]]\n",
      "\n",
      " [[0.27550587 0.09663458 0.18542939 0.05476915]\n",
      "  [0.09663458 0.09255531 0.09103836 0.04299877]\n",
      "  [0.18542939 0.09103836 0.20227635 0.0616792 ]\n",
      "  [0.05476915 0.04299877 0.0616792  0.03232217]]\n",
      "\n",
      " [[0.38741443 0.09223101 0.30244612 0.06089936]\n",
      "  [0.09223101 0.11040631 0.08386768 0.0557538 ]\n",
      "  [0.30244612 0.08386768 0.32595958 0.07283247]\n",
      "  [0.06089936 0.0557538  0.07283247 0.08488025]]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.datasets import load_iris\n",
    "from sklearn.mixture import GaussianMixture\n",
    "\n",
    "\n",
    "data = load_iris()\n",
    "n_components = 3 # 高斯分布的数量\n",
    "model = GaussianMixture(n_components=n_components)\n",
    "model.fit(data.data) \n",
    "print(model.predict(data.data)) # 预测类别\n",
    "print(model.means_) # 各高斯分布的均值\n",
    "print(model.covariances_) # 各高斯分布的方差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
